// 依赖模块
var express = require('express');
var path = require('path');

// 初始化句柄
var http = require('http');
var app = express();
var cors = require('cors');

// 设置监听端口
app.set('port', 8080);

// 设置静态页访问
app.set('views', __dirname + '\\views');

// ajax请求序列化json
app.use(express.json());
app.use(express.urlencoded())

// 设置跨域访问
app.use(cors());

//  静态资源
app.use(express.static(path.join(__dirname, '/views')));
app.use(require('./routes'))

// 加载环境变量
// 启动及端口
var server = http.createServer(app);
server.listen(app.get('port'), function () {
    console.log('server started,listen port: ' + app.get('port'));
});

// 导出app对象
module.exports = app;
